/**
 * Copyright 2010 upTick Pty Ltd
 *
 * Licensed under the terms of the GNU General Public License version 3 
 * as published by the Free Software Foundation. You may obtain a copy of the
 * License at: http://www.gnu.org/copyleft/gpl.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations 
 * under the License.
 */

package au.com.uptick.serendipity.client.sales.widgets;

import au.com.uptick.serendipity.client.Serendipity;
import com.allen_sauer.gwt.log.client.Log;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.toolbar.ToolStrip;
import com.smartgwt.client.widgets.toolbar.ToolStripButton;

public class ToolBar extends HLayout {

    private static final String TOOLBAR_HEIGHT = "25px";
    private static final String TOOLSTRIP_WIDTH = "*";

    private static final String SAVE_BUTTON = "toolbar/save.png";
    private static final String SAVE_AND_CLOSE_BUTTON = "toolbar/saveandclose.png";
    private static final String PRINT_PREVIEW_BUTTON = "toolbar/printpreview.png";
    private static final String EMAIL_BUTTON = "toolbar/sendemail.png";
    private static final String REPORTS_BUTTON = "toolbar/reports.png";
    private static final String HELP_BUTTON = "toolbar/help.png";

    private ToolStripButton saveAndCloseButton;

    public ToolBar() {
        super();

        Log.debug("ToolBar()");

        // initialise the ToolBar layout container
        this.setStyleName("crm-Entity-ToolBar");
        this.setHeight(TOOLBAR_HEIGHT);

        // initialise the ToolStrip
        ToolStrip toolStrip = new ToolStrip();
        toolStrip.setStyleName("crm-Entity-ToolStrip");
        toolStrip.setHeight(TOOLBAR_HEIGHT);
        toolStrip.setWidth(TOOLSTRIP_WIDTH);

        Img logo = new Img("toolbar/logo.png", 48, 36);
        logo.setStyleName("crm-Entity-ToolBar-Logo");
        // this.addMember(logo);
        toolStrip.addChild(logo);

        // initialise the Save button
        ToolStripButton saveButton = new ToolStripButton();
        saveButton.setIcon(SAVE_BUTTON);
        saveButton.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                SC.say("You clicked the Save button.");
            }
        }
        );
        toolStrip.addButton(saveButton);

        // initialise the Save and Close button
        this.saveAndCloseButton = new ToolStripButton();
        this.saveAndCloseButton.setIcon(SAVE_AND_CLOSE_BUTTON);
        this.saveAndCloseButton.setTitle(Serendipity.getConstants().SaveAndCloseButton());
        toolStrip.addButton(this.saveAndCloseButton);

        // initialise the Print Preview button
        ToolStripButton printPreviewButton = new ToolStripButton();
        printPreviewButton.setIcon(PRINT_PREVIEW_BUTTON);
        toolStrip.addButton(printPreviewButton);

        toolStrip.addSeparator();

        // initialise the Email button
        ToolStripButton emailButton = new ToolStripButton();
        emailButton.setIcon(EMAIL_BUTTON);
        toolStrip.addButton(emailButton);

        // initialise the Reports button
        ToolStripButton reportsButton = new ToolStripButton();
        reportsButton.setIcon(REPORTS_BUTTON);
        toolStrip.addButton(reportsButton);

        toolStrip.addSeparator();

        // initialise the Help button
        ToolStripButton helpButton = new ToolStripButton();
        helpButton.setIcon(HELP_BUTTON);
        helpButton.setTitle(Serendipity.getConstants().HelpButton());
        toolStrip.addButton(helpButton);

        this.addMember(toolStrip);
    }

    public ToolStripButton getSaveAndCloseButton() {
        return saveAndCloseButton;
    }
}
